package com.atguigu.gmall.model.cart;

import com.atguigu.gmall.model.activity.CouponInfo;
import com.atguigu.gmall.model.base.BaseEntity;
import com.atguigu.gmall.model.product.SkuInfo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(description = "购物车")
public class CartInfo extends BaseEntity {
    private static final long serialVersionUID = 1L;

    //    @ApiModelProperty(value = "用户id")
//    private String userId;  //冗余存储

    @ApiModelProperty(value = "skuid")
    private Long skuId;  //商品的id

    @ApiModelProperty(value = "第一次放入购物车时价格")
    private BigDecimal cartPrice;  //

    @ApiModelProperty(value = "数量")
    private Integer skuNum;

    @ApiModelProperty(value = "图片文件")
    private String imgUrl;

    @ApiModelProperty(value = "sku名称 (冗余)")
    private String skuName;

    @ApiModelProperty(value = "isChecked")
    private Integer isChecked = 1;

    //  ,fill = FieldFill.INSERT
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    private Timestamp createTime;  //时间，未来按照他排序

    //  ,fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    private Timestamp updateTime;

    // 实时价格 skuInfo.price
    BigDecimal skuPrice;  //商品的实时价格

    //给页面展示信息用的
    private BigDecimal orderPrice; //订单价格

    //  优惠券信息列表
//    private List<CouponInfo> couponInfoList;


    public static CartInfo convertSkuInfoToCart(SkuInfo info){
        CartInfo cartInfo = new CartInfo();

        cartInfo.setId(info.getId());
        cartInfo.setCartPrice(info.getPrice());
        cartInfo.setSkuName(info.getSkuName());
        cartInfo.setSkuId(info.getId());
        cartInfo.setIsChecked(1);  //1代表被选中，0就是没有选中
        cartInfo.setImgUrl(info.getSkuDefaultImg());
//        cartInfo.setCreateTime(new Timestamp(new Date().getTime()));
//        cartInfo.setUpdateTime(new Timestamp(new Date().getTime()));
//        阿里建议System.currentTimeMillis() 替换 new Date().getTime()
        cartInfo.setCreateTime(new Timestamp(System.currentTimeMillis()));
        cartInfo.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        return cartInfo;
    }

}
